package com.nd.order_sys_yhx.controller;


import com.nd.order_sys_yhx.common.result.ResultUtils;
import com.nd.order_sys_yhx.entity.OrderDetail;

import com.nd.order_sys_yhx.service.IOrderDetailService;
import com.nd.order_sys_yhx.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yhx
 * @since 2024-12-25
 */
@RestController
@RequestMapping("/order_detail")
public class OrderDetailController {
    @Autowired//自动导入
            IOrderDetailService service;

    @GetMapping("/")//   "/"为查询all
    public Object getList(){
        return ResultUtils.returnSuccessLayui(service.list(),service.list().size());
    }

    @GetMapping("/{id}")//根据id查询单个
    public Object getById(@PathVariable("id")Integer id){
        return service.getById(id);
    }

    @DeleteMapping("/{id}")
    public Object del(@PathVariable("id")Integer id){
        if(service.removeById(id)){
            return ResultUtils.returnSuccess();
        }
        else return ResultUtils.returnFail("删除失败");
    }

    @PostMapping("/")
    public Object add(@RequestBody OrderDetail orderDetail){
        if (service.save(orderDetail)){
            return ResultUtils.returnSuccess();
        }
        else return ResultUtils.returnFail("添加失败") ;
    }

    @PutMapping("/")
    public Object update(@RequestBody OrderDetail orderDetail){
        if(service.updateById(orderDetail)){
            return ResultUtils.returnSuccess();
        }
        else return  ResultUtils.returnFail("修改失败");

    }
}
